<template>
  <div>
    <div class="header">
      <div>首页</div>
      <div>
        <a @click="articles" to="/publisharticles">
          <img src="../assets/img/f1/article.png" alt="" />
          <span>发布文章</span> </a
        >&nbsp;&nbsp;
        <template v-if="unickname">
          <router-link :to="`/userpage/?uid=${uid}`">
            欢迎：{{ unickname }}
          </router-link>
        </template>
        <template v-if="!unickname">
          <router-link to="/login">用户登录</router-link>
        </template>
      </div>
    </div>
    <div class="search">
      <div class="box">
        <div>俄乌局势观察网</div>
        <div>
          <input
            type="text"
            placeholder="请输入搜索内容"
            v-model="searchItem"
          />
          <div>
            <router-link :to="`/searchpage/?searchitem=${searchItem}`"
              >搜索</router-link
            >
          </div>
        </div>
        <div>
          <span>今日热搜词</span>
          <div>
            <a v-for="v in hotarticles" :key="v.nid" @click="resou(v.nid)">
              {{ v.nname }}
            </a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["unickname", "uid"]),
  },
  data() {
    return {
      searchItem: "",
      hotarticles: [],
      num: 1,
    };
  },
  mounted() {
    this.hotarticle();
  },
  methods: {
    hotarticle() {
      const url = "http://192.168.1.2:8888/hotshort";
      this.axios.get(url).then((res) => {
        console.log(res);
        this.hotarticles = res.data.results;
      });
    },
    articles() {
      if (!this.$store.state.unickname) {
        this.$alert("请先登录或注册用户", "不能发布文章", {
          confirmButtonText: "确定",
        });
      } else {
        this.$router.push("/publisharticles");
      }
    },
    resou(nid) {
      this.$router.push(`/article?nid=${nid}`);
    },
  },
};
</script>

<style lang="scss" scoped>
.header {
  height: 40px;
  background-color: #90080e;
  display: flex;
  justify-content: space-between;
  > div {
    align-self: center;
  }
  > div:first-child {
    font-size: 16px;
    color: #fff;
    margin-left: 10px;
    cursor: pointer;
  }
  > div:last-child {
    display: flex;
    > a:first-child {
      display: flex;
      align-items: center;
      cursor: pointer;
      > img {
        margin-top: 2px;
        margin-right: 2px;
      }
    }
    > a {
      font-size: 16px;
      color: #fff;
      margin-right: 15px;
    }
  }
}
.search {
  background: url("../assets/img/f1/bg.png") center no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  > .box {
    display: flex;
    flex-direction: column;
    align-items: center;
    > div:first-child {
      font-size: 50px;
      color: #90080e;
      font-weight: bold;
      margin-bottom: 10px;
    }
    > div:nth-child(2) {
      display: flex;
      > input {
        width: 600px;
        height: 50px;
        border-top-left-radius: 30px;
        border-bottom-left-radius: 30px;
        border: 1px solid #eee;
        padding-left: 20px;
      }
      > div {
        width: 100px;
        height: 50px;
        border-top-right-radius: 30px;
        border-bottom-right-radius: 30px;
        background-color: #90080e;
        line-height: 52px;
        text-align: center;
        font-size: 18px;
        cursor: pointer;
        padding: 2px 0;
        > a {
          color: #fff;
        }
      }
    }
    > div:last-child {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-top: 10px;
      > span {
        font-size: 18px;
        color: #90080e;
        font-weight: bold;
        margin-bottom: 10px;
      }
      > div {
        display: flex;
        width: 400px;
        > a {
          background-color: rgba(255, 255, 255, 0.8);
          padding: 10px 15px;
          border-radius: 10px;
          font-weight: bold;
          white-space: nowrap;
          font-size: 16px;
          color: black;
          margin-left: 10px;
          cursor: pointer;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        > a:hover {
          color: #90080e;
        }
      }
    }
  }
}
</style>
